define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'file/item/index' + location.search,
                    add_url: 'file/item/add',
                    edit_url: 'file/item/edit',
                    del_url: 'file/item/del',
                    multi_url: 'file/item/multi',
                    import_url: 'file/item/import',
                    table: 'item',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                exportTypes:['excel'],
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title:'物品ID',operate: false},
                        {field: 'class', title: __('Class'),operate: false,visible:false},
                        {field: 'quality', title: __('Quality'),operate: false,visible:false},
                        {field: 'type', title: __('Type'),operate: false,visible:false},
                        {field: 'medindex', title: __('Medindex'),operate: false,visible:false},
                        {field: 'icon', title: __('Icon'),operate: false,visible:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%', placeholder: '模糊搜索'},
                        {field: 'desc', title: '描述',operate: false},
                        {field: 'level', title: __('Level'),operate: false,visible:false},
                        {field: 'price', title: __('Price'),operate: false,visible:false},
                        {field: 'sale_price', title: __('Sale_price'),operate: false,visible:false},
                        {field: 'rule', title: __('Rule'),operate: false,visible:false},
                        {field: 'num', title: __('Num'),operate: false,visible:false},
                        {field: 'script_id', title: __('Script_id'),operate: false,visible:false},
                        {field: 'skill_id', title: __('Skill_id'),operate: false,visible:false},
                        {field: 'is_cost', title: __('Is_cost'),operate: false,visible:false},
                        {field: 'need_skill', title: __('Need_skill'),operate: false,visible:false},
                        {field: 'need_skill_level', title: __('Need_skill_level'),operate: false,visible:false},
                        {field: 'own_num', title: __('Own_num'),operate: false,visible:false},
                        {field: 'obj_type', title: __('Obj_type'),operate: false,visible:false},
                        {field: 'type_desc', title: __('Type_desc'),operate: false,visible:false},
                        {field: 'quality_level', title: __('Quality_level'),operate: false,visible:false},
                        {field: 'recipe_id', title: __('Recipe_id'),operate: false,visible:false},
                        {field: 'color', title: __('Color'),operate: false,visible:false},
                        {field: 'subclass', title: __('Subclass'),operate: false,visible:false},
                        {field: 'is_boardcast', title: __('Is_boardcast'),operate: false,visible:false},
                        {
                            field: 'buttons',
                            width: "120px",
                            title: '操作',
                            table: table,
                            operate:false,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '详情',
                                    title:'详情',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    icon: 'fa fa-list',
                                    url: 'file/item/detail',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: true
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});